<html>
  <head>
    <title><%= h @place["name"]%></title>
    <script src="http://code.jquery.com/jquery-1.7.1.min.js" type="text/javascript"></script>
  </head>
  <body>
    <h1><%= h @place["name"]%></h1>

    <% unless @place["attribution"].nil? %>
      <%= @place["attribution"] %>
      <br/>
    <% end %>

    <a href="<%= @place["view"] %>">Share this</a>

    <h2>Address</h2>

    <%= @place['location']['address']['text'] %>

    <% unless @place['contacts'].nil? or @place['contacts'].empty? %>
      <h2>Contact Details</h2>
      <table>
        <% @place['contacts'].values.each do |contact_list| %>
          <% for contact in contact_list %>
            <tr><td><strong><%= h contact['label'] %></strong></td><td><%= h contact['value'] %></td></tr>
          <% end %>
        <% end %>
      </table>
    <% end %>

    <% unless @place['extended'].nil? %>
      <h2>Additional Info</h2>
      <table>
        <% @place['extended'].values.each do |extended_attr| %>
        <tr><td><strong><%= h extended_attr['label'] %></strong></td><td><%= extended_attr['text'] %></td></tr>
        <% end %>
      </table>
    <% end %>

    <% unless @place['media'].nil? %>
      <% unless @place['media']['editorials'].nil? %>
        <h2>Editorials</h2>
        <div>
          <% for editorial in @place['media']['editorials']['items'] %>
            <hr/>
            <%= editorial['description'] %><br/>
            <%= editorial['attribution'] %>
          <% end %>
        </div>
      <% end %>

      <% unless @place['media']['images']['items'].empty? %>
        <h2>Images</h2>
        <div id='images'>
          <%= erb :images, :locals => {:images => @place['media']['images']} %>
        </div>
      <% end %>

      <% unless @place['media']['reviews']['items'].empty? %>
        <h2>Reviews</h2>
        <div id='reviews'>
          <%= erb :reviews, :locals => {:reviews => @place['media']['reviews']} %>
        </div>
      <% end %>
    <% end %>

    <% unless @recommendations.empty? %>
      <h2>Recommendations</h2>
      <ul>
        <% for recommendation in @recommendations['items'] %>
          <li>
            <img src="<%= recommendation['icon'] %>"/>
            <a href="<%= backend_url('place', recommendation['href']) %>"><%= recommendation['title'] %></a>
          </li>
        <% end %>
      </ul>
    <% end %>
    
    <script type="text/javascript">
      $(document).ready(function() {
        $('a.more_images').live("click", function(event) {
          event.preventDefault();
          $.get($(this).attr('href'), function(data) {
            $('a.more_images').replaceWith(data);
          });
        });

        $('a.more_reviews').live("click", function(event) {
          event.preventDefault();
          $.get($(this).attr('href'), function(data) {
            $('a.more_reviews').replaceWith(data);
          });
        });
      });
    </script>
  </body>
</html>
